<template>
  <div class="content">
    <!--    条码列表弹窗-->
    <el-dialog
      v-dialogDrag
      :title="$t('market.codeList')"
      model
      :visible.sync="isclientlDialog"
      :close-on-click-modal="false"
      width="60%"
      :before-close="handleClose"
    >
      <el-button style="margin-bottom: 5px" size="mini" type="primary" @click="printDa(selPrint)">多条打印</el-button>
      <div>
        <jc-table
          :table-data="tableData"
          :table-header="tableHeader"
          table-height="53vh"
          serial
          table-selection
          @selectionChange="selectionDatas"
        >
          <template v-slot:btnState="col">
            <el-tag v-if="col.scope.row.fstatus === 0">未入库</el-tag>
            <el-tag v-else-if="col.scope.row.fstatus === 1">入库</el-tag>
            <el-tag v-else-if="col.scope.row.fstatus === 2">出库</el-tag>
            <el-tag v-else-if="col.scope.row.fstatus === 3">删除</el-tag>
          </template>
          <template v-slot:btnSlot="col">
            <el-button size="mini" type="primary" @click="printDa(col.scope.row.fnumber)">打印</el-button>
            <el-button size="mini" type="danger" @click="deleteDa(col.scope.row.fid)">删除</el-button>
          </template>
        </jc-table>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { deleteProductCode, queryProductCode } from '@/api/finished'

export default {
  props: {
    priDa: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      // 客户列表数据分页
      isclientlDialog: true,
      selPrint: [],
      tableData: [],
      tableHeader: [
        { label: this.$t('market.mobillNo'), prop: 'fprdno' },
        { label: this.$t('market.paezText1'), prop: 'salKhddh' },
        { label: this.$t('market.barcode'), prop: 'fnumber' },
        { label: this.$t('market.stockQty'), prop: 'qty' },
        { label: this.$t('market.funit'), prop: 'unitname' },
        { label: this.$t('shop.state'), type: 'state' },
        { label: this.$t('market.handle'), type: 'btn' }
      ],
      prodValue: {}
    }
  },
  created() {
    this.queryTBdCustomerList()
  },
  methods: {
    // 获取详情
    async queryTBdCustomerList() {
      const DATA = {
        ...this.priDa
      }
      queryProductCode(DATA).then(res => {
        if (res.code === 0) {
          this.tableData = res.data
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 多选
    selectionDatas(val) {
      this.selPrint = []
      val.forEach(res => {
        this.selPrint.push(res.fnumber)
      })
    },
    // 打印
    printDa(ev) {
      this.handleClose()
      this.$router.push({
        path: `/printLian/${ev}`
      })
    },
    // 删除
    deleteDa(fid) {
      this.$confirm('确定要删除么？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteProductCode({ fid }).then(res => {
          if (res.code === 0) {
            this.queryTBdCustomerList()
            this.$message({ showClose: true, message: res.message, type: 'success' })
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
          }
        })
      })
    },
    // 关闭前回调
    handleClose() {
      this.$emit('client')
    }
  }
}
</script>

<style scoped lang="scss">
.content {
  @include listBom;
}
</style>
